package com.wz.project.sap.CUSTOMER.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.sap.CUSTOMER.domain.ZflWmsGetCustomer;
import com.wz.project.sap.CUSTOMER.service.IZflWmsGetCustomerService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 客户主数据Controller
 * 
 * @author wz
 * @date 2022-09-19
 */
@Controller
@RequestMapping("/CUSTOMER/CUSTOMER")
public class ZflWmsGetCustomerController extends BaseController
{
    private String prefix = "CUSTOMER/CUSTOMER";

    @Autowired
    private IZflWmsGetCustomerService zflWmsGetCustomerService;

    @RequiresPermissions("CUSTOMER:CUSTOMER:view")
    @GetMapping()
    public String CUSTOMER()
    {
        return prefix + "/CUSTOMER";
    }

    /**
     * 查询客户主数据列表
     */
//    @RequiresPermissions("CUSTOMER:CUSTOMER:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZflWmsGetCustomer zflWmsGetCustomer)
    {
        startPage();
        List<ZflWmsGetCustomer> list = zflWmsGetCustomerService.selectZflWmsGetCustomerList(zflWmsGetCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户主数据列表
     */
    @RequiresPermissions("CUSTOMER:CUSTOMER:export")
    @Log(title = "客户主数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZflWmsGetCustomer zflWmsGetCustomer)
    {
        List<ZflWmsGetCustomer> list = zflWmsGetCustomerService.selectZflWmsGetCustomerList(zflWmsGetCustomer);
        ExcelUtil<ZflWmsGetCustomer> util = new ExcelUtil<ZflWmsGetCustomer>(ZflWmsGetCustomer.class);
        return util.exportExcel(list, "CUSTOMER");
    }

    /**
     * 新增客户主数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户主数据
     */
    @RequiresPermissions("CUSTOMER:CUSTOMER:add")
    @Log(title = "客户主数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZflWmsGetCustomer zflWmsGetCustomer)
    {
        return toAjax(zflWmsGetCustomerService.insertZflWmsGetCustomer(zflWmsGetCustomer));
    }

    /**
     * 修改客户主数据
     */
    @GetMapping("/edit/{KUNNR}")
    public String edit(@PathVariable("KUNNR") String KUNNR, ModelMap mmap)
    {
        ZflWmsGetCustomer zflWmsGetCustomer = zflWmsGetCustomerService.selectZflWmsGetCustomerById(KUNNR);
        mmap.put("zflWmsGetCustomer", zflWmsGetCustomer);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户主数据
     */
    @RequiresPermissions("CUSTOMER:CUSTOMER:edit")
    @Log(title = "客户主数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZflWmsGetCustomer zflWmsGetCustomer)
    {
        return toAjax(zflWmsGetCustomerService.updateZflWmsGetCustomer(zflWmsGetCustomer));
    }

    /**
     * 删除客户主数据
     */
    @RequiresPermissions("CUSTOMER:CUSTOMER:remove")
    @Log(title = "客户主数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zflWmsGetCustomerService.deleteZflWmsGetCustomerByIds(ids));
    }
}
